<?php
namespace Api\Controller;
use Think\Controller;
class QuestionController extends Controller {
    public function allquestion(){
      $coachid=$_GET['coachid'];
      $question = M('question');
      $map=array();
      $map['coachid']=$coachid;
      $map['answer'] = array('neq','');
      $question = $question->where($map)->join('user ON user.userid = question.userid')->field('questionid,question,username,coachid,answer,time')->order('time desc')->limit(5)->select();
      $this->ajaxReturn($question);
    }

    public function ask(){
      $coachid=$_GET['coachid'];
      $userid=$_GET['userid'];
      $qt=$_GET['question'];
      $question = M('question');

      $data['coachid']=trim($coachid);
      $data['userid']=trim($userid);
      $data['question']=trim($qt);
      $data['time']=date('Y-m-d H:i:s');

      $question=$question->add($data);
      if($question!==false){
          $re['success']='1';
          $this->ajaxReturn($re);
      }else{
          $re['success']='0';
          $this->ajaxReturn($re);
      }
    }
}
